﻿using System;
using System.IO;

namespace MikeKappel.Com.CS
{
    public static partial class Helper
    {
        /// <summary>
        /// Copy stream content from original stream to a target stream.
        /// </summary>
        /// <param name="source">Original Stream</param>
        /// <param name="target">Target Stream</param>
        public static void StreamCopy(Stream original, Stream target)
        {
            StreamCopy(original, target, false);
        }

        /// <summary>
        /// Copy stream content from original stream to a target stream.
        /// </summary>
        /// <param name="source">Original Stream</param>
        /// <param name="target">Target Stream</param>
        /// <param name="closeSource">Close Original String</param>
        public static void StreamCopy(Stream original, Stream target, Boolean closeSource)
        {
            Byte[] buffer = new Byte[0x1000];
            Int32 bytesRead = 0;
            while ((bytesRead = original.Read(buffer, 0, buffer.Length)) > 0)
                target.Write(buffer, 0, bytesRead);

            if (closeSource)
                original.Close();
        }
    }
}
